package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
   private StudentDao studentDao = new StudentDao();

    //判断id是否存在
    public boolean exit(String id) {
        Student[] arr = studentDao.getStus();
        boolean b = false;
        for (int i = 0; i < arr.length; i++) {
            Student s = arr[i];
            if (s != null && s.getId().equals(id)) {
                b = true;
            }
        }
        return b;
    }

    //返回数组
    public void addStudent(Student stu) {
         studentDao.addStudent(stu);
    }

    //判断数组是否为空
    public Student[] useStudent() {
        Student[] stus = studentDao.getStus();
        for (int i = 0; i < stus.length; i++) {
            Student s = stus[i];
            if (s != null) {
                return stus;
            }
        }
        return null;
    }
//删除
    public void deleteStudentById(String id) {
        studentDao.deleteStudentById(id);
    }
//修改
    public void changeStudentById(String id, Student s) {
        studentDao.changeStudentById(id,s);
    }
//查
    public void searchStudent() {
        Student[] stu=studentDao.getStus();
        for (int i = 0; i < stu.length; i++) {
            Student s = stu[i];
            if(s!=null){
                System.out.println(s.getId()+"\t"+s.getName()+"\t"+s.getAge()+"\t"+s.getBirthday());
            }
        }
    }
//数组是否已满
    public boolean full() {
        Student[] stus = studentDao.getStus();
        for (int i = 0; i < stus.length; i++) {
            if(stus[i]==null){
                return false;
            }
        }
        return true;
    }
}
